package com.axonactive.training.maganedbean;

import java.util.List;

import javax.annotation.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.inject.Inject;

import com.axonactive.training.model.Category;
import com.axonactive.training.model.Expense;
import com.axonactive.training.service.CategoryService;
import com.axonactive.training.service.ExpenseService;

@ManagedBean
@RequestScoped
public class ExpenseBean {
	private Expense expense;	
	private Long categoryId;
	
	@Inject
	ExpenseService expenseService;
	@Inject
	CategoryService categoryService;
	
	public List<Expense> getExpenseList(){
		return expenseService.getExpenseList();
	}
	
	public void saveExpense(){
		Category categorySelected = categoryService.getCategoryById(categoryId);
		expense.setCategory(categorySelected);
		expenseService.saveExpense(expense);
	}

	public Expense getExpense() {
		if(expense == null){
			expense = new Expense();
		}
		return expense;
	}

	public void setExpense(Expense expense) {
		this.expense = expense;
	}

	public Long getCategoryId() {
		return categoryId;
	}

	public void setCategoryId(Long categoryId) {
		this.categoryId = categoryId;
	}
	
	
}
